
import 'package:deviceinfo/deviceinfo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:massagist/manager/config.dart';
import 'package:massagist/pages/acctravel_page.dart';
import 'package:massagist/pages/massage_page.dart';
import 'package:massagist/pages/mine_page.dart';
import 'package:massagist/pages/path_page.dart';

import '../generated/l10n.dart';

class TabPage extends StatefulWidget {
  @override
  State<TabPage> createState() => TabPageState();
}

class TabPageState extends State<TabPage> {
  late BuildContext getContext;
  var allPages=[AcctravelPage(), MassagePage(), PathPage(), MinePage()];
  // var allPages=[];
  var currentIndex = int.parse(Config.settingInfo.tab);

  @override
  void initState() {
    super.initState();

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent, // 设置状态栏背景颜色为透明
      statusBarBrightness: Brightness.dark, // 设置状态栏文本亮度为暗色
      statusBarIconBrightness: Brightness.dark, // 设置状态栏图标亮度为暗色
    ));

    if (int.parse(Config.settingInfo.rank) == SHOW_STAR) {
      var device = new Deviceinfo();
      device.appRank();
    }
  }

  @override
  Widget build(BuildContext context) {
    getContext = context;
    return Scaffold(
      extendBodyBehindAppBar: true,
      body: allPages[currentIndex],
      bottomNavigationBar: Expanded(
        child: BottomNavigationBar(
          currentIndex: currentIndex,
          type: BottomNavigationBarType.fixed,
          unselectedItemColor: Color(0xFF333333),
          selectedItemColor: Color(0xFF00CA7E),
          selectedLabelStyle: TextStyle(fontSize: 9.sp, fontWeight: FontWeight.w500),
          unselectedLabelStyle: TextStyle(fontSize: 9.sp, fontWeight: FontWeight.w200),
          items: [
            BottomNavigationBarItem(
              icon: Image.asset( 'assets/images/tabs/acctravel_normal.png', width: 22.sp, height: 22.sp, ),
              activeIcon: Image.asset( 'assets/images/tabs/acctravel_select.png', width: 22.sp, height: 22.sp, ),
              label: S.current.TAB_ACCTRAVEL_TEXT,
            ),

            BottomNavigationBarItem(
              icon: Image.asset( 'assets/images/tabs/massage_normal.png', width: 22.sp, height: 22.sp, ),
              activeIcon: Image.asset( 'assets/images/tabs/massage_select.png', width: 22.sp, height: 22.sp, ),
              label: S.current.TAB_MASSAGE_TEXT,
            ),

            BottomNavigationBarItem(
              icon: Image.asset( 'assets/images/tabs/path_normal.png', width: 22.sp, height: 22.sp, ),
              activeIcon: Image.asset( 'assets/images/tabs/path_select.png', width: 22.sp, height: 22.sp, ),
              label: S.current.TAB_PATH_TEXT,
            ),

            BottomNavigationBarItem(
              icon: Image.asset( 'assets/images/tabs/mine_normal.png', width: 22.sp, height: 22.sp, ),
              activeIcon: Image.asset( 'assets/images/tabs/mine_select.png', width: 22.sp, height: 22.sp, ),
              label: S.current.TAB_MINE_TEXT,
            ),
          ],

          onTap: (index){
            setState(() {
              currentIndex = index;
            });
          },
        ),
      ),
    );
  }
}